package com.course.action;

import java.io.IOException;


import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.course.delegate.UserMgrDelegate;
import com.course.exception.ConnectionException;
import com.course.exception.LoginException;
import com.course.util.UtilConstants;



public class CancelFacultyAction extends HttpServlet {

	
	private static final long serialVersionUID = 1L;


	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		doPost(request, response);
	}

	
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		String path="";
		 boolean flag=false;

		  try{
			  
			  
			  HttpSession hs=request.getSession();
			  
			  String login=(String) hs.getAttribute("user");
			  
			  try{
			  int cid=Integer.parseInt(request.getParameter("courseid"));
			   flag= new UserMgrDelegate().deleteFaculty(cid,login);	
			  }catch (ConnectionException e) {
				e.printStackTrace();
			}catch (LoginException e) {
				e.printStackTrace();
			}
			  System.out.println("in Action class vcb..........."+flag);
			   if(flag){
				  request.setAttribute("status", UtilConstants._DELETE_FACULTY_SUCCESS);
				  path=UtilConstants._DELETE_FACULTY_HOME;
				 }
			  else{
				  request.setAttribute("status", UtilConstants._DELETE_FACULTY_FAILED);
				  path=UtilConstants._DELETE_FACULTY_HOME; 
				 }
			   }
		  catch (Exception e) {
			  request.setAttribute("status", UtilConstants._INVALIED_DATA);
			  path=UtilConstants._DELETE_FACULTY_HOME;
			 e.printStackTrace();
			}
	RequestDispatcher rd=request.getRequestDispatcher(path);
			rd.forward(request,response);
	}

}
